﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Automation;
using Compiled_Tests.RuleBase;
using System.Diagnostics;
using LEET.CommonInterfaces.TestControls;

namespace Compiled_Tests
{
    public class AutomationActionResult : IAutomationActionResult
    {
        Object ret;
        public bool IsFirstResult { get; set; }
        private int lineNumber;
        private int processId;

        public AutomationActionResult()
        {
            ret = null;
            IsFirstResult = false;
        }

        public AutomationActionResult(object result, int line, int id)
        {
            ret = result;
            IsFirstResult = false;
            lineNumber = line;
            processId = id;
        }

        public AutomationActionResult(object result)
        {
            ret = result;
            IsFirstResult = false;
        }

        public bool isEmpty { get { return ret == null; } }
        
        public bool isError { get { return ret != null && (ret is Exception || ret is String); } }
        public Exception Error {
            get
            {
                if (ret is Exception) return ret as Exception;
                Exception ex;
                ex = new Exception(ret as String);
                return ex;
            }
        }

        public bool isProcess { get { return ret is IProcess; } }
        public IProcess Process { get { return ret as IProcess; } }


        public bool isSignal { get { return ret is int; } }
        public AutomationActionResult(ScriptSignal sig)
        {
            switch (sig)
            {
                case ScriptSignal.Wait: ret = 1; break;
                case ScriptSignal.Closing: ret = 0; break;
            }
        }
        public ScriptSignal Signal { 
            get { 
                switch ((Int32)ret){
                    case 1: return ScriptSignal.Wait;
                    default: return ScriptSignal.Closing;
                }
            } 
        }

        public bool isRuleBase
        {
            get
            {
                return (ret as IRuleBase) != null;
            }
        }

        public IRuleBase RuleBase()
        {
            return ret as IRuleBase;
        }

        public bool isTestScript { get { return (ret as ITestScript) != null; } }
        public ITestScript TestScript()
        {
            return ret as ITestScript;
        }

        public override String ToString()
        {
            if (ret == null)
                return "NULL";
            return ret.ToString();
        }
    }

    
}
